
--注册常规合成
register_crad_rule('帝炎',{'三千焱炎火','净莲妖火','骨灵冷火','陨落心炎','青莲地心火','幽冥毒火','红莲业火','虚无吞炎',})
register_crad_rule('斗帝萧火火',{'萧火火','药老','玄重尺','帝炎'})


--入口
local mt = ac.skill['萧火火']
local crads = {
    '三千焱炎火','净莲妖火','骨灵冷火','陨落心炎','青莲地心火',
    '萧火火','药老','玄重尺',
    '幽冥毒火',
    '红莲业火',
    '虚无吞炎',
}

function mt:on_card(hero,player)
    if hero[self.name] then
        return
    end
    hero[self.name] = true
    for _,name in ipairs(crads) do
        player:set_data(name,true)
    end

    player:event '卡池-添加卡组'(function(_,_,pool)
        for _,name in ipairs(crads) do
            pool[#pool+1] = name
        end
    end)
    hero:event '天赋-检测合成后'(function(trg)
        local haves = hero:get_data('拥有天赋表') or {}
        for _,name in ipairs(crads) do
            if not haves[name] then
                return
            end
        end
        trg:remove()
        hero:set_data('完成-计数',hero:get_data('完成-计数',0) + 1)
    end)
    
end



local mt = ac.skill['火炎']
function mt:on_add()
    local hero = self.owner
    self:gc(hero:add_buff(self.name){
        art = self.art,
        tip = self:get_tip(),
        keep = true,
        on_add = function(buff)
            local has = 0
            local sx = ('%s加成'):format(self['属性1'])
            buff:gc(hero:event '天赋-检测合成'(function()
                local count = hero:get_data('异火-计数',0)
                local num = count * self.data1
                hero:add(sx,num - has)
                has = num
                buff.stack = count
            end))
            buff:gc(function()
                hero:add(sx,- has)
            end)
        end
    })


end

local mt = ac.skill['冷炎']
function mt:on_add()
    local hero = self.owner
    self:gc(hero:add_buff(self.name){
        art = self.art,
        tip = self:get_tip(),
        keep = true,
        on_add = function(buff)
            local has = 0
            local sx = ('%s加成'):format(self['属性1'])
            buff:gc(hero:event '天赋-检测合成'(function()
                local count = hero:get_data('异火-计数',0)
                local num = count * self.data1
                hero:add(sx,num - has)
                has = num
                buff.stack = count
            end))
            buff:gc(function()
                hero:add(sx,- has)
            end)
        end
    })
    
end

local mt = ac.skill['灼烧']

function mt:on_add()
    local hero = self.owner
    self:gc(ac.loop(time * 500,function()
        local damage = hero:get('攻击') * self.data1/100 * time
        hero:aoe_damage(hero,600,damage,self)
    end))
end


local mt = ac.skill['炎爆']
mt.missile_art = [[Abilities\Weapons\FireBallMissile\FireBallMissile.mdl]]
function mt:on_add()
    local hero = self.owner
    self:gc(ac.loop(self.cool*1000,function()
        if hero:is_alive() then
            local group = table.random_table(ac.selector('unit'):range(hero,900):enemy(hero):get(),7)
            local damage = hero:get(self['属性1']) * self.data1 / 100
            for _,u in ipairs(group) do
                hero:launch_missile(u,self.missile_art,1000,0.15,function()
                    hero:create_damage(u,damage,self)
                end)
            end
        end
    end))
end

local mt = ac.skill['万火臣服']
mt.model1 = [[6fa7000177e5918ab0285bae515ab527.mdl]]
function mt:on_add()
    local hero = self.owner
    self:gc(hero:event '单位-击杀'(function()
        hero:add_buff '火源印记'{
            art = self.art,
            skill = self,
            data1 = self.data1,
            data3 = self.data3,
            time = self.data2,
        }
    end))
    self:gc(hero:event '单位-攻击命中'(function(_,_,target)
        if self:is_cooling()==false then
            local buff = hero:find_buff('火源印记')
            if buff and buff.stack>=20 then
                self:cooling()
                buff:remove()
                local point = target:get_point()
                point:add_effect(self.model1):remove()
                for u in ac.selector('unit')
                    : range(target,300)
                    : enemy(hero)
                    : loop()
                do
                    u:add_buff '帝炎-灼烧'{
                        source = hero,
                        skill = self,
                        time = self.data5,
                    }
                end
            end
        end
    end))
end

local buff = ac.buff['火源印记']
buff.tip = [[每层提升'data1'%力量加成]]
buff.time = 5
buff.stack = 1
buff.effect_data = {
    ['hand left'] = [[Abilities\Weapons\PhoenixMissile\Phoenix_Missile_mini.mdl]],
    ['hand right'] = [[Abilities\Weapons\PhoenixMissile\Phoenix_Missile_mini.mdl]],
}


function buff:on_cover()
    local hero = self.owner
    self:set_remaining(self.time)
    if self.stack<self.data3 then
        self:on_add()
        self.stack = self.stack + 1
    end
    return false
end

function buff:on_add()
    local hero = self.owner
    self:gc(hero:add('力量加成',self.data1))
end



local buff = ac.buff['帝炎-灼烧']
buff.time = 3
buff.cover_type = 1
buff.cover_max = 0
buff.pulse = 1
buff.targetArt = [[Abilities\Spells\Other\ImmolationRed\ImmolationRedDamage.mdl]]

function buff:on_add()
    local hero = self.owner
    local stack = self:get_real_stack()
    if stack==1 then
        hero:add_effect(self.targetArt,'chest')
    end
end

function buff:on_pulse()
    local source = self.source
    local target = self.target
    local skill = self.skill
    local damage = source:get(skill['属性1']) * skill.data4 / 100
    target:damage{
        source = source,
        skill = self,
        damage = damage,
        ['附加'] = true,
    }
end



local mt = ac.skill['佛怒火莲']
mt.model1 = [[cc7e339aad9b287b36d1381e0abf7615.mdl]]
function mt:on_add()
    local hero = self.owner
    self:gc(ac.loop(self.data1*1000,function()
        if not hero:is_alive() then
            return
        end
        local point = hero:get_point()
        point:effect{
            model = self.model1,
            speed = 5,
            time = 1,
        }
        ac.wait(1000,function()
            local damage = hero:get(self['属性1']) * self.data2 / 100
            hero:aoe_damage(point,800,damage,self)
        end)
    end))
end


local mt = ac.skill['炎帝领域']

mt.cast_art = [[757c01ca5b6b33b3f5707f512fdf9e40.mdl]]
function mt:on_add()
    local hero = self.owner
    local time = 0.5
    self:gc(hero:add_effect(self.cast_art))
    self:gc(ac.loop(time * 500,function()
        local damage = hero:get(self['属性1']) * self.data1/100 * time
        hero:aoe_damage(hero,600,damage,self)
    end))
end






local mt = ac.skill['八极崩']
mt.model1 = [[20f69b3661532addf0eb646c010f424a.mdl]]
function mt:on_add()
    local hero = self.owner
    local count = 0
    self:gc(hero:event '单位-攻击命中'(function(_,_,target)
        count = count + 1
        if count>=self.data1 then
            count = 0
            local damage = hero:get(self['属性1']) * self.data2 / 100 +  hero:get(self['属性2']) * self.data3 / 100
            local point = target:get_point()
            local angle = hero:get_point() / point
            point:effect{
                model = self.model1,
                angle = angle-135,
            }
            target:damage{
                source = hero,
                damage = damage,
                skill = self,
            }
        end
    end))
end

